package com.dubbo.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dubbo.IHelloService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Component;

/**
 * 在提供者端通过配置version = "2.0.0"可以为某一接口设置版本号
 *
 * 然后在消费者端，通过指定version = "2.0.0"可以使用到具体版本的接口
 *
 * 配置存根：<dubbo:service interface="com.xxx" stub="com.xxx" />
 */

@Component
@Service(interfaceClass = IHelloService.class, version = "1.0.0")// sub="com.dubbo.IHelloConsumerStub"
public class IHelloServiceImpl implements IHelloService {

    @HystrixCommand
    @Override
    public String sayHello(String say) {
        System.out.println("============调用了provider的old版本方法==========");
        if (Math.random() > 0.5) {
            // 模拟出错，演示服务容错处理
            throw new RuntimeException();
        }
        return "hello " + say;
    }
}
